package com.wk.token;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;

import java.util.ArrayList;
import java.util.List;

public class SentinelToken {

	public static void createToken(){
		//所有限流规则的合集
		List<FlowRule> rules = new ArrayList<>();

		FlowRule rule = new FlowRule();
		//限流要保护的资源名称
		rule.setResource("name");
		//限流类型 根据什么限流
		rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
		//每秒2个QPS
		rule.setCount(2);

		//添加规则
		rules.add(rule);

		//读取规则
		FlowRuleManager.loadRules(rules);

	}

}
